import datetime
import struct
import time

file_name = "/home/ubuntu/umm_000000_29.bin"
copy_file = file_name+".copy"
f = open(file_name, "rb")
copyf = open(copy_file, "a")

x_arr = []
y_arr = []
z_arr = []
intensity_arr = []
while True:
    x_str = f.read(4)
    if x_str == b'':
        break
    y_str = f.read(4)
    z_str = f.read(4)
    intensity_str = f.read(4)
    x = struct.unpack('f', x_str)[0]
    y = struct.unpack('f', y_str)[0]
    z = struct.unpack('f', z_str)[0]
    intensity = struct.unpack('f', intensity_str)[0]
    x_arr.append(str(x))
    y_arr.append(str(y))
    z_arr.append(str(z))
    intensity_arr.append(str(intensity))

print(len(x_arr))
start = time.clock()
for i in range(0, len(x_arr)):
    copyf.write(x_arr[i])
    copyf.write(",")
    copyf.write(y_arr[i])
    copyf.write(",")
    copyf.write(z_arr[i])
    copyf.write(",")
    copyf.write(intensity_arr[i])
    copyf.write("\n")

end = time.clock()
print(end - start)
f.close()
